#ifndef CLIENT_H
#define CLIENT_H
/* INclude */
#include <QTimer>
#include <QMap>
#include <QCoreApplication>
#include <QIODevice>
#include <QUdpSocket>
#include <QObject>
#include <QTcpSocket>
#include "multicastsocket.h"
#include "application.h"
#include "..\commons\commons.h"



class Client : public QCoreApplication{
	Q_OBJECT

public:
	Client(int argc, char *argv[]);
	~Client();
	bool isCorrect();
	ApplicationManager *getAppManager();
	QHostAddress getServerAddress();
	void sendXml(QString &xml);
	void logMsg(QString msg);
	void setMode(bool);
	bool isLightMode() {return lightMode;};
public slots:
	void sendHello();
	void helloRequired();
	void forceJoinReceived();
	void handleBytesWritten(qint64);
	//La funzione riceve la struttura force_join 
	//che contiene tutte le info per effettuare
	//il trasferimento
	bool receiveFile(force_join *packet, QIODevice *output, bool onlyAck = false);
	
	
private:
	
	
	QHostAddress serverAddress;
	//QList<Application> app_list;
	QTimer helloTimer; //genera segnale ogn tot secondi
	
				
	QUdpSocket forceJoinSocket; //ascolta su una porta per sentire i messaggi di join
	// connesso alla funzione parse..

	MulticastSocket forceHelloSocket;

	quint32 id;
	quint16 join_port;
	quint16 servingReq;
	ApplicationManager *appmng;
	QFile *logFile;
	QTcpSocket *serverSocket;
	bool lightMode;
};



#endif 